package com.example.service.impl.projectResourceImpl;

import com.example.entity.ProjectResourceVO;
import com.example.entity.SysUser;
import com.example.mapper.projectResourceMapper.ProjectResourceMapper;
import com.example.service.projectResource.ProjectResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * --- 无事发生 ---
 *
 * @author YangYiBo
 * @date 2024/12/2
 * @desc
 */
@Service
public class ProjectResourceServiceImpl implements ProjectResourceService {

    @Autowired
    private ProjectResourceMapper projectResourceMapper;

    @Override
    public List<ProjectResourceVO> list(ProjectResourceVO projectResourceVO) {
        return projectResourceMapper.list(projectResourceVO);
    }

    @Override
    public int delById(int resourceId) {
        return projectResourceMapper.delById(resourceId);
    }

    @Override
    public int delBatch(ArrayList<Integer> ids) {
        return projectResourceMapper.delBatch(ids);
    }

    @Override
    public void add(ProjectResourceVO projectResourceVO) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes( )).getRequest( );
        SysUser user = (SysUser) request.getSession( ).getAttribute("sysUser");

        String userName = user.getUserName( );
        projectResourceVO.setCreateBy(userName);
        projectResourceVO.setUpdateBy(userName);
        projectResourceVO.setCreateTime(new Date(  ));
        projectResourceVO.setUpdateTime(new Date(  ));
        projectResourceMapper.add(projectResourceVO);
    }
}
